import CryptoJS from 'crypto-js';

//DES加密
export function encryptByDES(message, key) {
  var keyHex = CryptoJS.enc.Utf8.parse(key);
  var encrypted = CryptoJS.DES.encrypt(message, keyHex, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return encrypted.ciphertext.toString();
}

//DES解密
export function decryptByDES(ciphertext, key) {
  var keyHex = CryptoJS.enc.Utf8.parse(key);
  var decrypted = CryptoJS.DES.decrypt({
    ciphertext: CryptoJS.enc.Hex.parse(ciphertext)
  }, keyHex, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  var result_value = decrypted.toString(CryptoJS.enc.Utf8);
  return result_value;
}

export function toJson(data) {
  let strs = data.split('&');
  let theRequest = new Object();
  for (let i = 0; i < strs.length; i++) {
    theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
  }
  return theRequest
}

export function SHA256(data) {
  if (data == '') return '';
  let theRequest = CryptoJS.SHA256(data).toString()
  return theRequest
}

// export function getDESKey(id) {
//   switch (id) {
//     case 'jinqiao':
//       return 'h4BjRjw0@%￥#@11111';
//     case 'biaoyi':
//       return 'kSg7ZLd3@%￥#@11112';
//     case 'huayu':
//       return '$shfy#12368@ssbq';
//     case 'shzgy':
//       return 'BRWXx04NO3KMTHUp';
//     default:
//       return '';
//   }
// }

export const step1Key = "@#$KJHKsldk6545.**$$$";
export const step2Key = "@#$Ksfdjlskdf8*++**$$$";
export const step3Key = "hh@@%lksdjfdslkfjKK++==";

